import * as echarts from 'echarts'

import ChinaMapData from '../data/china.json'

echarts.registerMap('china',ChinaMapData)

export default function(el: HTMLElement){
  const echartInstanct = echarts.init(el)
  const setOptions = (options: echarts.EChartsOption) => {
    echartInstanct.setOption(options)
  }
  const updateSize = () => {
    echartInstanct.resize()
  }
  //监听窗口改变然后更新echarts
  window.addEventListener('resize',()=> {
    echartInstanct.resize()
  })

  return {
    echartInstanct,
    setOptions,
    updateSize
  }
}
